#ifndef VRPXML_H
#define VRPXML_H

#include <QObject>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QMap>
#include "VRPRouteGraph.h"
#include "VRPObjects.h"

class VRPXml : public QObject
{
    Q_OBJECT
public:
    explicit VRPXml(QObject *parent = 0);
    ~VRPXml();

    enum
    {
        XML_SUCCESS,
        XML_ERROR,
        XML_ERROR_FILE
    };

    int loadGraph(VRPRouteGraphTraits::Graph& graph, QList<VehiclePtr>& vehicleList, const QString& fileName);
    int saveGraph(VRPRouteGraphTraits::Graph& graph, const QList<VehiclePtr>& vehicleList, const QString& fileName);

private:
    void saveVertices(VRPRouteGraphTraits::Graph& graph, QXmlStreamWriter &xmlWriter);
    void saveEdges(VRPRouteGraphTraits::Graph& graph, QXmlStreamWriter &xmlWriter);
    void writeLineString(LineStringPtr lineString, QXmlStreamWriter &xmlWriter);

    bool readVertex(VRPRouteGraphTraits::Graph& graph,
                    QXmlStreamReader& reader,
                    QMap<QString, VRPRouteGraphTraits::Vertex> &vertexMap);
    bool readEdge(VRPRouteGraphTraits::Graph& graph,
                  QXmlStreamReader& reader,
                  QMap<QString, VRPRouteGraphTraits::Vertex> &vertexMap);
    bool readVehicle(QList<VehiclePtr>& vehicleList, QXmlStreamReader& reader);
    QString getTextElement(QXmlStreamReader& reader);
    CirclePointPtr getCirclePoint(QXmlStreamReader& reader, const QString &pointName, bool isDepo = false);
    LineStringPtr getLineString(QXmlStreamReader& reader, QString name = QString());
    LineStringPtr parseStringWithPoints(const QString &pointsStr, QString name = QString());
};

#endif // VRPXML_H
